package com.Adapter;

import java.util.List;

import android.content.Context;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bolao.R;
import com.entidades.Team;
 
public class TeamAdapter extends BaseAdapter {
	private List<Team> teams;
	private LayoutInflater mInflater;
	private Context mContext;
	static class ViewHolder{
		private ImageView img;
		private TextView teamName;			
	}
	
	public TeamAdapter(Context context, List<Team> teams) {
		mContext = context;
		mInflater = LayoutInflater.from(context);
		this.teams = teams;

	}
		
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return teams.size();
	}

	@Override
	public Team getItem(int arg0) {
		// TODO Auto-generated method stub
		return teams.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return teams.get(arg0).getId();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {


		ViewHolder holder;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.team_row_layout, null);
			holder = new ViewHolder();  
			holder.img = (ImageView) convertView.findViewById(R.id.teamFlag);
            holder.teamName = (TextView) convertView.findViewById(R.id.teamName);
            convertView.setTag(holder);
                  
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		Resources r = mContext.getResources();		
		Team team = teams.get(position);
		holder.img.setImageResource(r.getIdentifier(team.getFlag(), "drawable",  mContext.getPackageName()));
		holder.teamName.setText(team.getLocalizedName());

		
		return convertView;
 
		} 

	



}
